<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\material;

use app\model\mongo\MongoKsUserVideoModel;
use app\service\BaseService;
use MongoDB\BSON\Regex;
use think\db\exception\DbException;

class KuaiShouSchemaService extends BaseService
{
    /**
     * 客户物料有效视频数.
     *
     * @param string $userId 客户id
     * @param string $materialId 物料id
     * @throws DbException
     */
    public static function getEnableMaterialVideoNum(string $userId = '', string $materialId = ''): int
    {
        return (new MongoKsUserVideoModel())
            ->where('photo_name', new Regex('^' . $materialId, 'i'))
            ->where('user_id', $userId)
            ->where('new_status', MongoKsUserVideoModel::NEW_STATUS_NORMAL)
            ->whereIn('outer_loop_native', MongoKsUserVideoModel::NATIVE_NO)
            ->count();
    }
}
